<template>
  <view>
    <van-cell
      @click="onSelect(item)"
      :title="item.name"
      v-for="(item, index) in cityList"
      :key="index"
    />
  </view>
</template>
<script>
import { mapMutations } from "vuex";
import vanCell from "@/wxcomponents/vant/cell/index";
export default {
  components: {
    vanCell,
  },
  data() {
    return {
      cityList: [],
    };
  },
  onLoad() {
    this.getCommonCity();
  },
  methods: {
    ...mapMutations(["changCommonCity"]),
    onSelect(item) {
      this.changCommonCity(item);
      uni.navigateBack();
    },
    getCommonCity() {
      this.$api.getCommonCity().then((res) => {
        if (res.code == 200) {
          this.cityList = res.data;
        }
      });
    },
  },
};
</script>
